//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by NeXTSTEP on 15/9/29.
//  Copyright © 2015年 NeXTSTEP. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    @IBOutlet weak var mainTabBar: MainTabBar!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildViewControllers()
        
        mainTabBar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    
    
    func composeDidClick(){
        print(__FUNCTION__)
        let sb = UIStoryboard(name: "Compose", bundle: nil)
        let vc = sb.instantiateInitialViewController()!
        presentViewController(vc, animated: true, completion: nil)
    }
    
    private func addChildViewControllers(){
        addChildViewController("Home","首页","tabbar_home")
        addChildViewController("Message","消息","tabbar_message_center")
        addChildViewController("Discover","发现","tabbar_discover")
        addChildViewController("Profile","我的","tabbar_profile")
        
    }
    
    private func addChildViewController(sbName: String, _ title: String, _ imageName: String) {
        //添加子视图控制器
//        self.tabBar.tintColor = UIColor.orangeColor()
        let sb = UIStoryboard(name: sbName, bundle: nil)
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        //只有设置 显示的的子视图控制器 才能够同事设置导航栏的title 和tabBarItem的title
        //        nav.title = "首页"
        nav.topViewController?.title = title
        nav.tabBarItem.image = UIImage(named: imageName)
//        nav.tabBarItem.selectedImage = UIImage(named: imageName + "highlighted")
        self.addChildViewController(nav)
    }
}
